package com.mantru.iotpot.Cook.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mantru.iotpot.R;

import java.util.List;

public class StepDiagramGridViewAdapte extends BaseAdapter {
    private Context mcontext;
    private List<String> date;
    private LayoutInflater inflater;

    public StepDiagramGridViewAdapte(Context context, List<String> items) {
        mcontext = context;
        date = items;
        inflater = LayoutInflater.from(context); // 初始化 inflater
    }
    @Override
    public int getCount() {
        return date.size();
    }

    @Override
    public Object getItem(int position) {
        return date.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapte_step_diagram_gridview_text, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.name = convertView.findViewById(R.id.step_diagram_gridview_text);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.name.setText(date.get(position));
//        // 动态设置宽度和高度
//        ViewGroup.LayoutParams params = convertView.getLayoutParams();
////        params.width = 110; // 设置宽度
////        params.height = 48; // 设置高度
//        convertView.setLayoutParams(params);
        return convertView;
    }

    private static class ViewHolder {
        TextView name;
    }
}
